package com.eric.demo.netty.ch7;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.msgpack.MessagePack;
import org.msgpack.template.Template;
import org.msgpack.template.Templates;

/**
 * @author ZhangGuangyin on 2018/9/9
 */
public class MsgpackEncoder extends MessageToByteEncoder<Object> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Object msg, ByteBuf byteBuf) throws Exception {
        MessagePack msgPack=new MessagePack();
        byte[] raw=msgPack.write(msg);
        //System.out.println(new String(raw));
        //UserInfo u = msgPack.read(raw, UserInfo.class);
        byteBuf.writeBytes(raw);
    }
}
